package com.example.demospring.controller;

import com.example.demospring.business.entity.Talents;
import com.example.demospring.business.service.TalentsServer;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/talents")
public class TalentsController {

    private final TalentsServer talentsServer;

    @Autowired
    public TalentsController(TalentsServer talentsServer) {
        this.talentsServer = talentsServer;
    }

    // 查询整张表
    @GetMapping("/all")
    public List<Talents> showAllTalents() {
        return talentsServer.showTalents();
    }

    // 查询姓名中含有keyword的人
    @GetMapping("/search")
    public List<Talents> showTalentByNameContaining(@RequestParam String keyword) {
        return talentsServer.showTalentByNameContaining(keyword);
    }

    // 重置密码为111111
    @GetMapping("/reset")
    public int updatePassword(@RequestParam int id) {
        return talentsServer.updatePassword(id);
    }

    // 在表中插入一条数据
    @PostMapping("/insert")
    public boolean insertTalent(@RequestBody Talents talent) {
        return talentsServer.insertTalent(talent);
    }

    // 根据id删除
    @DeleteMapping("/delete/{id}")
    public int deleteTalentById(@PathVariable int id) {
        return talentsServer.delTalent(id);
    }
}
